package com.dingreading.cloud.admin.service.impl;

import com.dingreading.cloud.admin.entity.CorporationContract;
import com.dingreading.cloud.admin.entity.table.CorporationContractTableDef;
import com.dingreading.cloud.admin.mapper.CorporationContractMapper;
import com.dingreading.cloud.admin.service.CorporationContractService;
import com.dingreading.cloud.common.util.DateUtil;
import com.dingreading.cloud.common.util.PageUtil;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryCondition;
import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.core.update.UpdateChain;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 服务层实现。
 *
 * @author Administrator
 * @since 2024-11-18
 */
@Service
public class CorporationContractServiceImpl extends BaseServiceImpl<CorporationContractMapper, CorporationContract, CorporationContractTableDef> implements CorporationContractService {

    @Override
    protected CorporationContractTableDef getTable() {
        return CorporationContractTableDef.corporationContract;
    }

    @Override
    public Page<CorporationContract> pageList(PageUtil pageUtil, String corpUid, String keyword) {
        QueryCondition condition = QueryCondition.createEmpty();
        if (StringUtils.isNotBlank(keyword))
            condition.and(table.contractCode.like(keyword));
        if (StringUtils.isNotBlank(corpUid))
            condition.and(table.corpUid.eq(corpUid));

        QueryWrapper wrapper = QueryWrapper.create().where(condition).orderBy(table.id.desc());

        return getMapper().paginate(Page.of(pageUtil.getPage(), pageUtil.getRows()), wrapper);
    }

    @Override
    public void updateSignStatus(Long id, Integer signStatus) {
        UpdateChain.of(CorporationContract.class)
                .set(table.signStatus, signStatus)
                .where(table.id.eq(id))
                .update();
    }

    @Override
    public List<CorporationContract> listByCorpUid(String corpUid) {
        return getMapper().selectListByCondition(table.corpUid.eq(corpUid));
    }

}
